package com.kakaxi.mybilibili.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.github.czy1121.view.RoundButton;
import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.bean.FindCenterItemBean;

import java.util.List;

/**
 * 发现中心列表适配器
 * Created by kakaxi on 16/11/26.
 */

public class FindCenterRecyAdapter extends BaseQuickAdapter<FindCenterItemBean, BaseViewHolder> {

    public FindCenterRecyAdapter(List<FindCenterItemBean> data) {
        super(R.layout.item_recy_find_center, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, FindCenterItemBean findCenterItemBean) {
        baseViewHolder
                .setText(R.id.txt_find_center_title, findCenterItemBean.getTitle());
        Glide.with(mContext).load(findCenterItemBean.getCover()).crossFade().into((ImageView)
                baseViewHolder.getView(R.id.srimg_find_center_cover));

        String state = findCenterItemBean.getState();
        if (state != null) {
            RoundButton roundButton = baseViewHolder.getView(R.id.roubtn_find_center_state);
            if (state.equals("0")) {
                roundButton.setVisibility(View.VISIBLE);
//                roundButton.setBackgroundResource(R.color.bg_common_window);
                roundButton.setText("已结束");
            } else if (state.equals("1")) {
                roundButton.setVisibility(View.VISIBLE);
//                roundButton.setBackgroundResource(R.color.colorPrimary);
                roundButton.setText("进行中");
            }
        }
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        if (recyclerView.getLayoutManager() == null) {
            recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        }
    }
}
